//
//  RootCollectionReusableView.m
//  NineGroupProject
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 lushan. All rights reserved.
//

#import "RootCollectionReusableView.h"
#import "Masonry.h"
@implementation RootCollectionReusableView

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        UILabel *lable = [[UILabel alloc]init];
        lable.text = @"——————————————————————————";
        lable.textColor = [UIColor grayColor];
        lable.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lable];
        [lable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10 * WID);
            make.top.mas_equalTo(3 * HEI);
            make.width.mas_equalTo(WIDTH - 20 * WID);
            make.height.mas_equalTo(2 * HEI);
        }];
        
        // 精选按钮
        self.siftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.siftBtn.frame = CGRectMake(60 * WID, 20 * HEI, 40 * WID, 10 * HEI);
        [self.siftBtn setTitle:@"精选" forState:UIControlStateNormal];
        [self.siftBtn setTitleColor:[UIColor colorWithRed:165 / 255.0 green:89 / 255.0 blue:19 / 255.0 alpha:1.0] forState:UIControlStateNormal];
        self.siftBtn.tag = 1001;
        [self.siftBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.siftBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.siftBtn];
        
        // 喜欢按钮
        self.likeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.likeBtn.frame = CGRectMake(250 * WID, 20 * HEI, 80 * WID, 10 * HEI);
        [self.likeBtn setTitle:@"大家喜欢" forState:UIControlStateNormal];
        [self.likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.likeBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        self.likeBtn.tag = 1002;
        self.likeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.likeBtn];
        
        self.littleView = [[UIView alloc] initWithFrame:CGRectMake(65 * WID, 35 * HEI, 30 * WID, 2 * HEI)];
        self.littleView.backgroundColor = [UIColor colorWithRed:165 / 255.0 green:89 / 255.0 blue:19 / 255.0 alpha:1.0];
        [self addSubview:self.littleView];
        
    }
    return self;
}

-(void)btnAction:(UIButton *)btn{
    
    if (btn.tag == self.likeBtn.tag) {
        [self.likeBtn setTitleColor:[UIColor colorWithRed:165 / 255.0 green:89 / 255.0 blue:19 / 255.0 alpha:1.0] forState:UIControlStateNormal];
        self.littleView.frame = CGRectMake(263 * WID, 35 * HEI, 55 * WID, 2 * HEI);
        [self.siftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.isLike = YES;
        [[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"like"];
        
    }
    else if (btn.tag == self.siftBtn.tag)
    {
        
        [self.siftBtn setTitleColor:[UIColor colorWithRed:165 / 255.0 green:89 / 255.0 blue:19 / 255.0 alpha:1.0] forState:UIControlStateNormal];
        self.littleView.frame = CGRectMake(65 * WID, 35 * HEI, 30 * WID, 2 * HEI);
        [self.likeBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        self.isLike = NO;
        [[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:@"like"];
        
    }
    // 发通知告知按钮的变换
    [[NSNotificationCenter defaultCenter] postNotificationName:@"changeCell" object:nil];
    
}


@end
